import api from "../../utils/api";
import util from "../../utils/util";
import constant from "../../utils/constant";

Page({
  data: {
    currentNotice: null, //当前通知对象
    PROJECT_TITLE: constant.PROJECT_TITLE,// 项目主标题
    PROJECT_SUB_TITLE: constant.PROJECT_SUB_TITLE, // 项目副标题
    MINIO_BANNER: constant.MINIO_BANNER, //横幅轮播图片MINIO地址
    banners: null, //横幅列表对象

    currentArticleIdx:1,//当前公告的value值，用于切换公告
    articles: null,
    seckills: null, //秒杀活动列表对象

    MINIO:constant.MINIO_COURSE_COVER,
    activeSeckillIdx: 0//当前秒杀活动的value值，用于切换秒杀活动
  },


  //查询1条通知记录
  topNotice1: function () {
    let that = this;
    api.get('notice', '/top/1')
        .then(res => that.setData({currentNotice: res[0]['content']}))
        .catch(err => util.error('查询失败', err));
  },

  //查询5条轮播图记录
  topBanner5: function () {
    let that = this;
    api.get('banner', '/top/5')
        .then(res => that.setData({banners: res}))
        .catch(err => util.error('查询失败', err));
  },

  // 查询5条通知记录
  topArticle5: function () {
    let that = this;
    api.get('article', '/top/5')
        .then(res => that.setData({articles: res}))
        .catch(err => util.error('查询失败', err));
  },

  // 查询10条未开始的营销活动
  nearSeckill10: function () {
    let that = this;
    api.get('seckill', '/near/10')
        .then(res => that.setData({seckills: res}))
        .catch(err => util.error('查询失败', err));
  },


  // 切换公告
  changeArticle: function (ev) {
    this.setData({'activeArticleName': ev.detail});
  },

  // 切换秒杀活动
  changeSeckill: function (ev) {
    this.setData({'activeSeckillIdx': ev.detail});
  },

  onLoad: function (options) {
    //加载函数
    this.topNotice1();
    this.topBanner5();
    this.topArticle5();
    this.nearSeckill10();
    this.getTabBar().setData({"activeTab": 0});
  }
});
